package principal;

import Composite.Dossier;
import Composite.Element;
import Composite.Photo;
import Composite.RacinePicasial;
import Popup.PopupGeneral;
import images.TabsDeDroite;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.tree.*;

public class ControleurArbreBoutonDroit extends MouseAdapter {

    private JTree arbre;
    private TabsDeDroite lesTabs;
    private JPopupMenu maPopup;

    public ControleurArbreBoutonDroit(JTree arbre, TabsDeDroite lesTabs) {

        this.lesTabs = lesTabs;
        this.arbre = arbre;

    }

    public void mouseClicked(MouseEvent e) {
        // clic sur le bouton droit
        if (e.getButton() == MouseEvent.BUTTON3) {
            try {
                TreePath path = arbre.getPathForLocation(e.getX(), e.getY());
                DefaultMutableTreeNode noeud = ((DefaultMutableTreeNode) path.getLastPathComponent());
                Element el = (Element) noeud.getUserObject();
                this.arbre.setSelectionPath(path);
                
                maPopup=PopupGeneral.getPopup(el,lesTabs);
                maPopup.show(e.getComponent(), e.getX(), e.getY());
   
            } catch (NullPointerException ex) {
//This means the user did not click on a node
            }
        }
    }
}   
